package com.ce.study.procum;

/**
 * @author Administrator
 * 验证非线程同步
 * 每次运行的结果都不一样，不是预料结果
 */
public class TestUnSynInt {
	public int count = 0;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TestUnSynInt synInt = new TestUnSynInt();
		for (int i = 0; i < 100; i++) {
			AddThread add = synInt.new AddThread("n"+i);
			add.start();
		}
		
	}

	public class AddThread extends Thread {
		String name;
		public AddThread(String name) {
			this.name = name;
		}

		@Override
		public void run() {
			for (int i = 0; i < 100; i++) {
				int tmp = count;
				tmp += 1;
				count = tmp;
/*				try {
					sleep(10); //增加了开销
				} catch (InterruptedException e) {
					e.printStackTrace();
				}*/
				System.out.println("AddThread-"+name+":"+count);
			}
		}
	}
	
}
